package za.ac.wits.was.courses;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import za.ac.wits.was.courses.allocations.CourseAllocations;
import za.ac.wits.was.disciplines.Discipline;

/**
 *
 * @author Salman Noor : School of Electrical and Information Engineering
 * @Copyright: Wits University 2013 - All Rights Reserved
 * @email: salmannoor74415@gmail.com
 * @License: BSD License (http://www.linfo.org/bsdlicense.html)
 */
@Entity
@Table(name = "course")
public class Course implements Serializable {
    
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "course_id")
    private Long course_id;
    
    @Column(name = "course_name")
    private String course_name;
    
    @Column(name = "course_code")
    private String course_code;
    
    @Column(name = "course_hours")
    private Integer course_hours;
    
    @Column(name = "course_slot")
    private String course_slot;
    
    @Column(name = "start_time")
    private String start_time;
    
    @Column(name = "end_time")
    private String end_time;
    
    @Column(name = "weekday")
    private String weekday;
    
    @Column(name = "semester")
    private String semester;
    
    @ManyToOne
    @JoinColumn(name = "discipline_id")
    private Discipline discipline;

    @Transient
    private Long discipline_id;
    
    @Transient
    private String discipline_code;
    
    @Transient
    private String course_full_name;
    
    @OneToMany(mappedBy="course",fetch= FetchType.LAZY)
    private Set<CourseAllocations> course_allocations;
    
    public Long getCourse_id() {
        return course_id;
    }

    public void setCourse_id(Long course_id) {
        this.course_id = course_id;
    }

    public String getCourse_name() {
        return course_name;
    }

    public void setCourse_name(String course_name) {
        this.course_name = course_name;
    }

    public String getCourse_code() {
        return course_code;
    }

    public void setCourse_code(String course_code) {
        this.course_code = course_code;
    }
    @JsonIgnore
    public Discipline getDiscipline() {
        return discipline;
    }
    @JsonIgnore
    public void setDiscipline(Discipline discipline) {
        this.discipline = discipline;
    }
    @JsonProperty("discipline_id")
    public Long getDiscipline_id() {
        if (this.discipline != null){
            this.discipline_id =this.discipline.getDiscipline_id();        
        }
        return this.discipline_id;
    }

    public void setDiscipline_id(Long discipline_id) {
        this.discipline_id = discipline_id;
    }
    @JsonProperty("discipline_code")
    public String getDiscipline_code() {
      if (this.discipline != null){
        this.discipline_code= this.discipline.getDiscipline_code();
      }
        return discipline_code;
    }

    public void setDiscipline_code(String discipline_code) {
        this.discipline_code = discipline_code;
    }

    public Integer getCourse_hours() {
        return course_hours;
    }

    public void setCourse_hours(Integer course_hours) {
        this.course_hours = course_hours;
    }

    public String getCourse_slot() {
        return course_slot;
    }

    public void setCourse_slot(String course_slot) {
        this.course_slot = course_slot;
    }
    @JsonIgnore
    public Set<CourseAllocations> getCourse_allocations() {
        return course_allocations;
    }
    @JsonIgnore
    public void setCourse_allocations(Set<CourseAllocations> course_allocations) {
        this.course_allocations = course_allocations;
    }
    @JsonProperty("course_full_name")
    public String getCourse_full_name() {
        this.course_full_name = this.course_code + " - "+this.course_name;
        return this.course_full_name;
    }
    @JsonIgnore
    public void setCourse_full_name(String course_full_name) {
        this.course_full_name = course_full_name;
    }

    public String getStart_time() {
        return start_time;
    }

    public void setStart_time(String start_time) {
        this.start_time = start_time;
    }

    public String getEnd_time() {
        return end_time;
    }

    public void setEnd_time(String end_time) {
        this.end_time = end_time;
    }

    public String getWeekday() {
        return weekday;
    }

    public void setWeekday(String weekday) {
        this.weekday = weekday;
    }

    public String getSemester() {
        return semester;
    }

    public void setSemester(String semester) {
        this.semester = semester;
    }
    
    
    
    
    
}
